package id.mankel.commons.security.session;

import id.mankel.commons.constants.Asciis;
import id.mankel.commons.crypto.digest.Digests;

import java.util.StringJoiner;
import java.util.UUID;

/**
 * @author Mankel
 */
public abstract class AbstractSessionManager<S> implements SessionManager<S> {

    /**
     * 2种情况：
     * <ol>
     *     <li>只是token，摘要算法即可</li>
     *     <li>token可以解析，需要用到加解密算法</li>
     * </ol>
     *
     * @param complex
     * @return
     */
    protected String generateToken(int complex) {
        StringJoiner stringJoiner = new StringJoiner(Asciis.POUND.s);
        for (int i = 0; i < complex; i++) {
            stringJoiner.add(UUID.randomUUID().toString());
        }
        return Digests.md5(stringJoiner.toString());
    }

}
